﻿using System;
using System.Data;
using System.Text;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;
using ChannelVN.Cached.Base;

namespace GUI.Controls.News
{
    public partial class BoxNews3 : ControlBase
    {
        private const string Format = "<li>{3}<a href=\"{0}\" title=\"{2}\" class=\"title\">{1}</a></li>";
        private const int ImageWidth = 180;
        private const int ImageHeight = 120;
        //public int Top = 10;
        //public int BoxId { get; set; }
        public string BoxTitle { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            
            
        }

        public  bool DataBind(DataTable dt)
        {
            if(dt!=null && dt.Rows.Count >0)
            {
                var sb = new StringBuilder();
                foreach (DataRow r in dt.Rows)
                {
                    var avatar = PresentationUtils.Photo.BuildNewsAvatar(r, ImageWidth, ImageHeight, lazyLoad: true);
                    sb.AppendFormat(Format,
                                    r[SqlConstants.NewsPublish.Url],
                                    r[SqlConstants.NewsPublish.Title],
                                    r[SqlConstants.NewsPublish.EncodedTitle],
                                    avatar);
                }
                ltrData.Text = sb.ToString();
                ltrBoxTitle.Text = BoxTitle;
                return true;
            }
            return false;
        }

        public override string CacheConfigName
        {
            get { return "Controls-News-BoxNews3"; }
        }

        public override bool IsCachedChanged(long newsId, string zoneId, long tagId)
        {
            return !string.IsNullOrEmpty(zoneId);
        }
    }
}